package com.cj.mobile.iabp.mvp.model;

import com.cj.mobile.iabp.app.global.AccountManager;
import com.cj.mobile.iabp.mvp.contract.AddArchiveInfoContract;
import com.cj.mobile.iabp.mvp.model.api.service.AccountService;
import com.cj.mobile.iabp.mvp.model.entity.DictInfo;
import com.jess.arms.cj.ApiOperator;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 2025/09/30 18:01
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class AddArchiveInfoModel extends BaseModel implements AddArchiveInfoContract.Model {
    @Inject
    ApiOperator apiOperator;                                                                        // 数据转换

    @Inject
    AccountManager mAccountManager;


    @Inject
    public AddArchiveInfoModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.apiOperator = null;
        this.mAccountManager = null;
    }

    @Override
    public Observable<List<DictInfo>> getDictList() {
        Map<String, Object> params = new HashMap<>();
        params.put("type", 1);

        return apiOperator.chain(params, request -> mRepositoryManager.obtainRetrofitService(AccountService.class).getDictList(mAccountManager.getToken(), request));
    }

    @Override
    public Observable<Integer> addArchive(String per, String patienId, String doctorId, String deptId, String regCode, String patientName,
                                           String status, String alive, String ga, String leftSize, String leftScore,
                                          String diagMain, String diagContent, String timeIcu, String timeMc, String runTime, String diagSec) {
        Map<String, Object> params = new HashMap<>();
        params.put("per", per);
        params.put("patienId", patienId);
        params.put("doctorId", doctorId);
        params.put("deptId", deptId);
        params.put("regCode", regCode);
        params.put("patientName", patientName);
        params.put("status", status);
        params.put("alive", alive);
        params.put("ga", ga);
        params.put("leftSize", leftSize);
        params.put("leftScore", leftScore);
        params.put("diagMain", diagMain);
        params.put("diagContent", diagContent);
        params.put("timeIcu", timeIcu);
        params.put("timeMc", timeMc);
        params.put("runTime", runTime);
        params.put("diagSec", diagSec);

        return apiOperator.chain(params, request -> mRepositoryManager.obtainRetrofitService(AccountService.class).addArchive(mAccountManager.getToken(), request));
    }

    @Override
    public Observable<Integer> updateArchive(String per, String id, String patienId, String doctorId, String deptId, String regCode,
                                             String patientName, String status, String alive, String ga, String leftSize, String leftScore, String diagMain, String diagContent, String timeIcu, String timeMc, String runTime, String diagSec) {
        Map<String, Object> params = new HashMap<>();
        params.put("per", per);
        params.put("id", id);
        params.put("patienId", patienId);
        params.put("doctorId", doctorId);
        params.put("deptId", deptId);
        params.put("regCode", regCode);
        params.put("patientName", patientName);
        params.put("status", status);
        params.put("alive", alive);
        params.put("ga", ga);
        params.put("leftSize", leftSize);
        params.put("leftScore", leftScore);
        params.put("diagMain", diagMain);
        params.put("diagContent", diagContent);
        params.put("timeIcu", timeIcu);
        params.put("timeMc", timeMc);
        params.put("runTime", runTime);
        params.put("diagSec", diagSec);

        return apiOperator.chain(params, request -> mRepositoryManager.obtainRetrofitService(AccountService.class).updateArchive(mAccountManager.getToken(), request));
    }
}